package org.lanqiao.tjut.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lanqiao.tjut.bean.TBStudentBean;
import org.lanqiao.tjut.model.ModelFactory;

import com.alibaba.fastjson.JSON;

/**
 * 学生信息修改跳转 FriendsInfoModalModifyAjaxQueryServlet
 */
@WebServlet("/PersonalInfoModalModifyAjaxQueryServlet")
public class PersonalInfoModalModifyAjaxQueryServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 获取参数
		// 获取主键id
		String stuId = request.getParameter("sid");
		// 根据操作类型进行不同的分支流程处理
		// 调用model层，从数据库中将该id的学生信息查询出来
		TBStudentBean stuB = ModelFactory.getStudentInfoModelInstance().getStudentInfoById(stuId);
		// 发回响应内容之前，需要将返回的java的数据结果对象转换为json对象
		// 将查询结果集转换为json对象
		String json = JSON.toJSONStringWithDateFormat(stuB, "yyyy-MM-dd HH:mm:ss");
		System.out.println("ajax josn:::" + json);
		// 使用writer对象将服务器响应内容发回客户端
		PrintWriter pw = response.getWriter();
		// 因为stuB转换的是对象键值对类型，需要前后添加 [] 才能解析为 json对象
		//pw.write("["+json+"]");
		pw.write(json);
		pw.flush();
		pw.close();
	}

}
